﻿Public Class BlockEightHomeworkSectionSeven
    Dim QuestionNumber As Integer
    Dim dtmTest, dtmTest2 As Date
    Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Declare the Array as 10 rows and 3 columns
    Dim ArrayMax As Integer = 8 'One number past the end of actual info in array
    Dim HWQuestions(ArrayMax, 3) As String
    Dim intResponse As Integer
    Dim intQuestionCount As Integer = 0
    Dim intAnswerCount As Integer = 0
    Dim intReferenceCount As Integer = 0
    Dim intFirstRun As Integer = 1
    Dim strUser As String = "Enter Last Name"
    Dim strAnswer, strAnswer2, strAnswer3, strAnswer4, strAnswer5, _
     strAnswer6, strAnswer7, strAnswer8 As String

    Shared Property MidiParent As MainForm

    Private Sub CloseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub BlockTwoHomeworkSectionOne_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtObj.Text = "Objectives:" + vbCrLf + "- Given proper student instructional materials, identify the operating principles of the spectrum analyzer to TACAN signal measurements." _
            + vbCrLf + "- Given proper student instructional materials, identify the operating principles of the peak power meter."
        If (System.IO.File.Exists(filename & "\Homework\Block 8\Block 8 Section 7.txt")) Then
            intResponse = MsgBox("This assignment has already been completed.  Are you sure you want to delete the current assignment and reaccomplish it?", 4, "Confirm Assignment Deletion")
            If intResponse = MsgBoxResult.Yes Then
                System.IO.File.Delete(filename & "\Homework\Block 8\Block 8 Section 7.txt")
                System.IO.File.Create(filename & "\Homework\Block 8\Block 8 Section 7.txt").Dispose()
            ElseIf intResponse = MsgBoxResult.No Then
                Me.Close()
            End If
        End If
        If (Not System.IO.File.Exists(filename & "\Homework\Block 8\Block 8 Section 7.txt")) Then
            System.IO.File.Create(filename & "\Homework\Block 8\Block 8 Section 7.txt").Dispose()
        End If
        If (Not System.IO.File.Exists(filename & "\Instructor\Block 8\Block 8 Section 7.txt")) Then
            System.IO.File.Create(filename & "\Instructor\Block 8\Block 8 Section 7.txt").Dispose()
        End If
        strUser = InputBox("Please enter last name", strUser)
        If strUser Is "" Then
            Me.Close()
        End If
        '************************************************
        '****** Questions Are Loaded Here****************
        '******* Column 1 is Questions (Preloaded)*******
        '******* Column 2 is Accepts Students Answer*****
        '******* Column 3 is Reference ******************

        HWQuestions(1, 1) = ""
        HWQuestions(1, 2) = ""
        HWQuestions(1, 3) = ""

        HWQuestions(2, 1) = ""
        HWQuestions(2, 2) = ""
        HWQuestions(2, 3) = ""

        HWQuestions(3, 1) = ""
        HWQuestions(3, 2) = ""
        HWQuestions(3, 3) = ""

        HWQuestions(4, 1) = ""
        HWQuestions(4, 2) = ""
        HWQuestions(4, 3) = ""

        HWQuestions(5, 1) = ""
        HWQuestions(5, 2) = ""
        HWQuestions(5, 3) = ""

        HWQuestions(6, 1) = "Close"

        Next_Question(HWQuestions)
    End Sub

    Private Sub btnNextQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnNextQuestion.Click
        Next_Question(HWQuestions)
    End Sub
    Private Sub Clear_Display()
        txtQuestion.Clear()
        txtAnswer.Clear()
    End Sub

    Public Function Next_Question(HWQuestions As String(,))
        txtAnswer.Focus()
        If intQuestionCount > 0 Then
            WriteToFile()
        End If
        If btnNextQuestion.Text = "Done" Then
            Me.Close()
            OpenResults()
        End If
        intQuestionCount = intQuestionCount + 1
        If intQuestionCount = 5 Then
            btnNextQuestion.Text = "Done"
        End If
        If intQuestionCount = 1 Then
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            Q1Table.Visible = True
            Q5Table.Visible = False
            lblAnswer.Visible = False
            txtAnswer.Visible = False
        ElseIf intQuestionCount = 5 Then
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            Q1Table.Visible = False
            Q5Table.Visible = True
            lblAnswer.Visible = False
            txtAnswer.Visible = False
            txtObj.Visible = False
        ElseIf intQuestionCount = 2 Or intQuestionCount = 3 Or intQuestionCount = 4 Then
            Q1Table.Visible = False
            txtAnswer.Visible = True
            lblAnswer.Visible = True
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            intAnswerCount = intAnswerCount + 1
            HWQuestions(intAnswerCount, 2) = txtAnswer.Text
            intReferenceCount = intReferenceCount + 1
            txtReference.Text = HWQuestions(intReferenceCount, 3)
        End If
        Return intQuestionCount & intAnswerCount
    End Function

    Private Sub WriteToFile()
        Dim Integrity As String = (filename & "\Instructor\Block 8\Block 8 Section 7.txt")
        Dim Results As String = (filename & "\Homework\Block 8\Block 8 Section 7.txt")

        '***********Output to hidden file for Instructor Check***********
        If System.IO.File.Exists(Integrity) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Integrity, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            If intQuestionCount = 2 Or intQuestionCount = 3 Or intQuestionCount = 4 Then
                hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
                hiddenWriter.WriteLine("Answer:" & txtAnswer.Text)
                hiddenWriter.WriteLine("Reference: " & txtReference.Text)
                hiddenWriter.WriteLine()
            ElseIf intQuestionCount = 1 Then
                hiddenWriter.WriteLine("Input: 2mW / Output 4mW:" & TextBox22.Text)
                hiddenWriter.WriteLine("Input: 12W / Output 6W:" & TextBox23.Text)
                hiddenWriter.WriteLine("Input: 25W / Output 50W:" & TextBox24.Text)
                hiddenWriter.WriteLine("Input: 20mW / Output .2W:" & TextBox25.Text)
                hiddenWriter.WriteLine("Input: 20mW / Output .4W:" & TextBox26.Text)
            ElseIf intQuestionCount = 5 Then
                hiddenWriter.WriteLine("dBm +1:" & TextBox1.Text & vbTab & vbTab & "dBm -1:" & TextBox6.Text)
                hiddenWriter.WriteLine("dBm +2:" & TextBox2.Text & vbTab & vbTab & "dBm -2:" & TextBox5.Text)
                hiddenWriter.WriteLine("dBm +3:" & TextBox3.Text & vbTab & vbTab & "dBm -3:" & TextBox4.Text)
                hiddenWriter.WriteLine("dBm +4:" & TextBox7.Text & vbTab & vbTab & "dBm -4:" & TextBox14.Text)
                hiddenWriter.WriteLine("dBm +5:" & TextBox8.Text & vbTab & vbTab & "dBm -5:" & TextBox15.Text)
                hiddenWriter.WriteLine("dBm +6:" & TextBox9.Text & vbTab & vbTab & "dBm -6:" & TextBox16.Text)
                hiddenWriter.WriteLine("dBm +7:" & TextBox10.Text & vbTab & vbTab & "dBm -7:" & TextBox17.Text)
                hiddenWriter.WriteLine("dBm +8:" & TextBox11.Text & vbTab & vbTab & "dBm -8:" & TextBox18.Text)
                hiddenWriter.WriteLine("dBm +9:" & TextBox12.Text & vbTab & vbTab & "dBm -9:" & TextBox19.Text)
                hiddenWriter.WriteLine("dBm +10:" & TextBox13.Text & vbTab & vbTab & "dBm -10:" & TextBox20.Text)
                hiddenWriter.WriteLine("dBm +11:" & TextBox27.Text & vbTab & vbTab & "dBm -11:" & TextBox21.Text)
            End If

            If intQuestionCount = 5 Then
                hiddenWriter.WriteLine("Block 8 Section 7 Homework Complete")
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If

            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Integrity")
        End If

        '******Output to file for Student to review***********
        If System.IO.File.Exists(Results) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Results, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine()
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            If intQuestionCount = 2 Or intQuestionCount = 3 Or intQuestionCount = 4 Then
                hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
                hiddenWriter.WriteLine("Answer:" & txtAnswer.Text)
                hiddenWriter.WriteLine()
            ElseIf intQuestionCount = 1 Then
                hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
                hiddenWriter.WriteLine("Input: 2mW / Output 4mW: " & TextBox22.Text)
                hiddenWriter.WriteLine("Input: 12W / Output 6W: " & TextBox23.Text)
                hiddenWriter.WriteLine("Input: 25W / Output 50W: " & TextBox24.Text)
                hiddenWriter.WriteLine("Input: 20mW / Output .2W: " & TextBox25.Text)
                hiddenWriter.WriteLine("Input: 20mW / Output .4W: " & TextBox26.Text)
                hiddenWriter.WriteLine()
            ElseIf intQuestionCount = 5 Then
                hiddenWriter.WriteLine("Question: " & txtQuestion.Text)
                hiddenWriter.WriteLine("dBm +1: " & TextBox1.Text & "  dBm -1: " & TextBox6.Text)
                hiddenWriter.WriteLine("dBm +2: " & TextBox2.Text & "  dBm -2: " & TextBox5.Text)
                hiddenWriter.WriteLine("dBm +3: " & TextBox3.Text & "  dBm -3: " & TextBox4.Text)
                hiddenWriter.WriteLine("dBm +4: " & TextBox7.Text & "  dBm -4: " & TextBox14.Text)
                hiddenWriter.WriteLine("dBm +5: " & TextBox8.Text & "  dBm -5: " & TextBox15.Text)
                hiddenWriter.WriteLine("dBm +6: " & TextBox9.Text & "  dBm -6: " & TextBox16.Text)
                hiddenWriter.WriteLine("dBm +7: " & TextBox10.Text & "  dBm -7: " & TextBox17.Text)
                hiddenWriter.WriteLine("dBm +8: " & TextBox11.Text & "  dBm -8: " & TextBox18.Text)
                hiddenWriter.WriteLine("dBm +9: " & TextBox12.Text & "  dBm -9: " & TextBox19.Text)
                hiddenWriter.WriteLine("dBm +10: " & TextBox13.Text & "  dBm -10: " & TextBox20.Text)
                hiddenWriter.WriteLine("dBm +11: " & TextBox27.Text & "  dBm -11: " & TextBox21.Text)
                hiddenWriter.WriteLine()
            End If

            If intQuestionCount = 5 Then
                hiddenWriter.WriteLine("Block 8 Section 7 Homework Complete")
            End If

            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Results")
        End If

        If intQuestionCount > 0 Then
            txtAnswer.Clear()
        End If

    End Sub

    Private Sub OpenResults()
        Dim p As Process = Process.Start(filename & "\Homework\Block 8\Block 8 Section 7.txt")
    End Sub
End Class
